﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Practico2.DataTypes;
using Practico2.Business;

namespace Practico2.WebAccess
{
    public partial class AdministradorPaises : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) 
            { 
            
            }
        }

        protected void GridViewPaises_SelectedIndexChanged(object sender, EventArgs e)
        {     
            Session.Add("idPais",GridViewPaises.Rows[GridViewPaises.SelectedIndex].Cells[1].Text);
            txtNombrePais.Text = GridViewPaises.Rows[GridViewPaises.SelectedIndex].Cells[2].Text;
            txtAbreviacion.Text = GridViewPaises.Rows[GridViewPaises.SelectedIndex].Cells[3].Text;

        }

        protected void btnAceptar_Click(object sender, EventArgs e)
        {
            DTPais nuevoPais = new DTPais();

            nuevoPais.NombrePais = txtNombrePais.Text;
            nuevoPais.AbreviacionPais = txtAbreviacion.Text;

            if (Session["idPais"] != null)
            {
                nuevoPais.IdPais = int.Parse(Session["idPais"].ToString());
                PaisManager.ActualizarPais(nuevoPais);
                Session.Remove("idPais");
            }
            else 
            {
                PaisManager.AgregarPais(nuevoPais);
            }
                        
            Response.Redirect("AdministradorPaises.aspx");

        }

        protected void btnCancelar_Click(object sender, EventArgs e)
        {
            if (Session["idPais"] != null)
            {
                Session.Remove("idPais");
            }
        }
    }
}